const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');

const hashLen = 10
const hashPassword = (pwd) => {
    return bcrypt.hashSync(pwd, hashLen)
}
const comparePassword = (pwd, hash) => {
    return bcrypt.compareSync(pwd, hash, (err, isMatch) => isMatch)
}

const secret = ('../keys/secret');
const createToken = (data, time) => {
    return jwt.sign(data, secret, { expiresIn: time })
}

const verifyToken = (token) => {
    try {
        return jwt.verify(token, secret);
    } catch (e) {
        console.log(e);
        return false;
    }
}
module.exports = {
    hashPassword,
    comparePassword,
    createToken,
    verifyToken
}